home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / diskmags / 3565-4.665 / dmg-4385 / issue_10 / 17.pne < prev    next >
Text File  |  1987-04-21  |  6KB  |  124 lines

  1.  
  2.                        WRITING A PROGRAM IN STOS
  3.  
  4.                           ARTICLE BY DEANO
  5.  
  6.    Well you've opened the STOS manual.  You've read it and seen all  the 
  7.    clever  commands and accessories you can use.  You've read and  heard 
  8.    that all this can enable you to write your very own masterpiece.
  9.  
  10.    But  how do you start,  what do you do,  how do you tell STOS  to  do 
  11.    this.....this  are  the questions the beginner  asks.  Well  in  this 
  12.    article I'm going to waffle on about the subject of writing your  own 
  13.    pieces of code. And show you how to write a simple game.
  14.  
  15.    First......how  do  we start?  Well....first we need  to  learn  some 
  16.    commands.  A program is just a group of commands that tell STOS  what 
  17.    to do. We start off with simple commands and we type out the examples 
  18.    in the STOS manual.  This helps to give us a good idea of  commanding 
  19.    STOS and telling it what to do.
  20.  
  21.    Lets  say  we wanted STOS to print something on the screen  over  and 
  22.    over again. We can use the PRINT and GOTO commands like this...
  23.  
  24.    10 print"STOSSER"
  25.    20 goto 10
  26.  
  27.    Here we have a simple program.  First it prints the word STOSSER onto 
  28.    the screen, and then it goes onto the next line that tells STOS to go 
  29.    back to line 10 and print STOSSER on the screen again.
  30.  
  31.    So  as you can see,  we have grouped two commands together to make  a 
  32.    small program.....actually a small program like this is better  known 
  33.    as  a  routine.  A program such as a game is just a  large  group  of 
  34.    routines. Lets try a routine that counts up to ten.
  35.  
  36.    10 for X=1 to 10
  37.    20 home:print X:wait 5
  38.    30 next X
  39.  
  40.    What we have here is a loop that adds one to the varible X, prints it 
  41.    one  the screen,  then stops when X reaches 10.  The HOME command  is 
  42.    used to tell STOS to keep the counter to the same part of the screen, 
  43.    and the WAIT command stops STOS from printing too fast.
  44.  
  45.    So.....once  we  have learnt the commands we can  easily  group  them 
  46.    together.  Once you've been learning them,  typing out examples,  and 
  47.    looking at other routines, you'll find it all comes clearer.
  48.  
  49.    Lets program a small game.  First we have to decide what the  program 
  50.    is going to be, and what it does. The game in question is a Guess the 
  51.    Number  game where STOS will first choose a random number,  then  ask 
  52.    the player to guess it.  If the players guess is wrong then STOS will 
  53.    tell him so. First....lets set up the screen.
  54.  
  55.    10 key off : hide : mode 0
  56.  
  57.    Next we can put the games name up, known as the title screen.
  58.  
  59.    20 locate 0,1 : centre"NUMBER GUESSER"
  60.  
  61.    Now we need to tell STOS to choose a random number, like this.
  62.  
  63.    30 RN=rnd(10) : if RN=0 then goto 30
  64.  
  65.    This line will choose a different number from 1 to 10 every time STOS 
  66.    comes  across  it.  With  programming we  are  sometimes  faced  with 
  67.    problems,  in this case, the RND command will sometimes choose nought 
  68.    as a random number.  The problem is that we only want numbers from  1 
  69.    to 10.  So therefore we add an IF THEN statement to tell STOS that if 
  70.    it chooses nought....then go back and try again.
  71.  
  72.    When STOS has chosen a number between 1 and 10,  it needs to ask  the 
  73.    player to guess the number.
  74.  
  75.    40 locate 2,4 : print"I am thinking of a number between 1 and 10"
  76.    50 locate 2,5 : print"Can you guess what it is?"
  77.  
  78.    Next we need a way of letting the player entering his guess.
  79.  
  80.    60 input A
  81.  
  82.    This command waits for the player to enter a number and press return. 
  83.    Now  so  far  we have the RN varible which holds  the  random  number 
  84.    chose by the game, and the A varible which holds the number chosen by 
  85.    the player. But what if the player has typed in a number which is out 
  86.    of range......we can check for this with these two lines.
  87.  
  88.    70 if A<1 then print"Your guess is too low, try again" : goto 60
  89.    80 if A>10 then print"Your guess is too high, try again" : goto 60
  90.  
  91.    So  if  the  number in the A varible is out of range  then  the  game 
  92.    imforms  the player to try again then goes back to the input at  line 
  93.    60.  Now we need a line to check if the player has  guessed the right 
  94.    number........like so. 
  95.  
  96.    90 if A<>RN then print"Thats not it, try again" : goto 60
  97.  
  98.    This  line  checks if the A varible contains the same number  as  the 
  99.    varible chose by the game.  Here we are telling the game that if  the 
  100.    players  guess is other than the number the game has chosen  then  to 
  101.    give them a chance to try again.
  102.  
  103.    Finally we need to check if the player has guessed the right number.
  104.  
  105.    100 if A=RN then print"Well done, you've guessed the number" : stop
  106.  
  107.    So  there  we  have it.  A small game produced by  just  a  group  of 
  108.    routines.  We can easily improve it, such as getting the game to loop 
  109.    back  to the start after the player wins.  We could also  add  extras 
  110.    such as a score by simply adding points to a varible and printing  it 
  111.    on the screen like this.
  112.  
  113.    110 SC=SC+10 : print"Your score is now:";SC
  114.    120 wait 50 : cls : goto 20
  115.  
  116.    If you are just starting on programming.  Then you will be pleased to 
  117.    know that there is a book to help you. Its called The Beginners Guide 
  118.    to STOS and you can get it from MT SOFTWARE. Another good book is the 
  119.    Game Makers Manual also from MT SOFTWARE.
  120.  
  121.    This is DEANO signing off...........
  122.  
  123.  
  124.